#ifndef __CLOCK_H__
#define __CLOCK_H__

#include "ch32v_def.h"
    
#ifdef __cplusplus
extern "C"
{
#endif
  
    typedef struct
    {
        __IO uint32_t CTRL;  /*!< Offset: 0x000 (R/W)  SysTick Control and Status Register */
        #if defined(CH32V3xx)
        __IO uint32_t SR;
        #endif
        __IO uint32_t CNTL;
        __IO uint32_t CNTH;
        __IO uint32_t CMPLR;
        __IO uint32_t CMPHR; 
    } SysTick_Type_Union;

    extern SysTick_Type_Union *SysTickUnon;

    uint32_t SysTick_Config(uint32_t ticks);

    uint32_t getCurrentMillis(void);
    uint32_t getCurrentMicros(void);

    void __func_interrupt SysTick_Handler(void);
    void clockIncrementTick(void);
#ifdef __cplusplus
}
#endif

#endif // __CLOCK_H__